﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Admin_login : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        checklogin();
    }
    protected void checklogin()
    {
        if (Request.Form["gotoadminlogin"] + "" == "登陆")
        {
            if (Request.Form["uname"] + "" == "" || Request.Form["upassword"] + "" == "")
            {
                Response.Write("<script>alert('对不起，请输入用户名密码!')</script>");
            }
            else
            {
                string sql_checkuser = "select userid,roleid from adminuser where  flag=0 and username='" + functions.chgSql(Request.Form["uname"].Trim()) + "' and password='" + functions.chgSql(Request.Form["upassword"].Trim()) + "'";
                DataSet dset1 = null;

                //DataClass.ExecuteSQL(sql_checkuser, "t1", out dset1);

                if (dset1 == null)
                {
                    //lblAlert.Text = "打开数据库错误,请重试.";
                    Response.Write("<script language=\"javascript\">");
                    Response.Write("alert(\"打开数据库错误\");");
                    Response.Write("</script>");
                    return;
                }
                else
                {
                    //
                    if (dset1.Tables["t1"].Rows.Count > 0)
                    {
                        //登陆成功
                        Session["Admin_UserID"] = dset1.Tables["t1"].Rows[0]["userid"];

                        string roleId = dset1.Tables["t1"].Rows[0]["roleid"].ToString();
                        Session["Admin_RoleID"] = roleId;
                        Response.Redirect("GiftAdd.aspx");

                        return;
                    }
                    else
                    {
                        //登陆失败
                        //lblAlert.Text = "登陆失败,用户名或者密码错误.";
                        Response.Write("<script language=\"javascript\">");
                        Response.Write("alert(\"登陆失败,用户名或者密码错误\");");
                        Response.Write("</script>");
                        return;
                    }
                }
            }
        }
    }

}
